package com.kool.leitu.base.exception;

import lombok.Getter;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *
 */
@Getter
public enum ErrorCodeEnum {
    /**
     *
     */
    SYSTEM_ERROR(1000001,"系统错误:%s"),
    BASE_ERROR(2000001,"基础功能错误:%s"),
    REGISTER_ERROR(2000002,"注册失败:%s"),
    LOGIN_ERROR(2000003,"登录失败:%s");

    private Integer errorCode;
    private String errorMsg;

    ErrorCodeEnum(Integer errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public static Map<Integer, ErrorCodeEnum> codeToEnum = Stream.of(ErrorCodeEnum.values()).collect(Collectors.toMap(ErrorCodeEnum::getErrorCode, self -> self));

    public static ErrorCodeEnum getEnumByCode(Integer errorCode) {
        return codeToEnum.get(errorCode);
    }

    public static String getMsgByCode(Integer errorCode) {
        return codeToEnum.get(errorCode) == null ? null : codeToEnum.get(errorCode).getErrorMsg();
    }
}
